package mns.modules.input.weatherbug;

import mns.*;

/**
 * A WeatherBug API Module, using XML
 * 
 * WeatherBug API Documentation:
 * http://weather.weatherbug.com/corporate/products/API/help.aspx#forecast
 * 
 * Uses HTTP calls to get XML via a zipcode -> location -> info path.
 * 
 * Can be configured for day of week 7 day forecast or instant alerts
 * 
 * @author Dan Moore
 *
 */
public class WeatherAlertsModule implements MNSInputModule {

	//private static final String API_KEY = "A5465474673";
	
	public String getName() {
		return "WeatherBug Alerts Module";
	}

	public String getOptionsFormHTML() {
		String html = "Zip Code: <input type=\"text\" name=\"zipcode\" value=\"30332\" />";
		return html;
	}

	public String getDescriptionHTML() {
		// TODO Auto-generated method stub
		return "";
	}

	/**
	 * Queries weatherbug Alert web API.
	 * Example file: http://A5465474673.api.wxbug.net/getAlertsRSS.aspx?ACode=A5465474673&zipCode=30332&UnitType=0&OutputType=1
	 * @param zipcode
	 * @return
	 */
	public MNSMessage getAlertsByZip(int zipcode) {
		return null;
	}
	
	/**
	 * Default to no msg, but can be chosen by engine which type of message to send.
	 * Should this be split into two modules?
	 */
	public MNSMessage getMessage(UserOptions opts) {
		UserOption opt;
		int zipcode;
		
		try {
			opt = opts.getOption("zipcode");
			zipcode = Integer.parseInt(opt.getValue());
		} catch(NullPointerException e) {
			System.err.println("Bad User Options, not getting msg from WeatherAlertsModule.");
			return null;
		}
		
		return getAlertsByZip(zipcode);

	}

	public NotificationType getType() {
		return NotificationType.ALERT;
	}

}
